package com.ming.attendance.service.impl;

import com.ming.attendance.mapper.WxGroupMapper;
import com.ming.attendance.po.ResponseBean;
import com.ming.attendance.po.WxGroup;
import com.ming.attendance.service.WxGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WxGroupServiceImpl implements WxGroupService {
    @Autowired
    private WxGroupMapper gm;

    @Override
    public ResponseBean<Integer> addOpengid(String openid, String opengid) {
        // 先判断库中有没有该opengid及与open的绑定数据
        List<String> opengids = gm.getOpengids(openid);
        if(opengids.size()!=0){
            for (String s : opengids) {
                if(s.equals(opengid)){
                    return new ResponseBean<>(606,"已经存在该关系，无需添加");
                }
            }
        }
        WxGroup group = new WxGroup();
        group.setOpenid(openid);
        group.setOpengid(opengid);
        int result = gm.saveGroup(group);
        if(result>0){
            return new ResponseBean<>(result);
        }else{
            return new ResponseBean<>(602,"添加失败");
        }
    }
}
